package com.zrgj.exception;

import com.zrgj.vo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionCtrl {

    static final Logger log = LoggerFactory.getLogger(ExceptionCtrl.class);

    /*
    当controller抛出异常(不论检查异常、运行时异常)时，由该方法处理
    优先级比 4xx.html、5xx.html （页面） 优先级高

    原controller不会打印错误
     */
    @ExceptionHandler(Exception.class)
    public JsonResult exception(Exception e) {

        log.error("", e);
        JsonResult jr = new JsonResult(1, "发送错误，请重试！");
        return jr;
    }
}
